<%-- 
    Document   : new_visit
    Created on : Mar 13, 2013, 2:44:30 PM
    Author     : Mansur
--%>

<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>.: Ship Visit :.</title>    
        <script type="text/javascript">
            $(function() {
                $("#datepicker").datepicker({
                    showOn: "button",
                    buttonImage: "${pageContext.request.contextPath}/images/icon/calendar.gif",
                    buttonImageOnly: true,
                    changeMonth: true,
                    dateFormat: 'dd/mm/yy',
                    changeYear: false,
                    maxDate: new Date(),
                    minDate: minDate()
                });
            });
            
            function validateEmpty(){
                var validate = true;
                if($('#vesselId').val() === '' || $('#datepicker2').val() === '' || $('#location').val() === ''){
                    alert('All form fields are required!');
                    validate  = false;
                }else{
                    autoComplete();
                }
                return validate;
            }
            
            function unblockUI() {
                $.unblockUI();
            }
            
            function blockUI () {
                $.blockUI();
            }
            
            function minDate(){
                var year = ${actionBean.currentYear};
                var date = new Date(year,0,1);
                return date;
            }
            
            function autoComplete(){
                var match = ${actionBean.sizeMatch};
                if(match !== 999999){
                    for(var i = 1; i <= match; i++){
                        if($('#details_'+i).val() === ''){
                            $('#details_'+i).val("NONE");
                        }
                    }
                }
                
                var subMatch = ${actionBean.sizeSubMatch};
                if(subMatch !== 999999){
                    for(var i = 1; i <= subMatch; i++){
                        if($('#sdetails_'+i).val() === ''){
                            $('#sdetails_'+i).val("NONE");
                        }
                    }
                }
            }
        </script>
        <script type="text/javascript">
            function popupWin(id) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?newDocument&idStaff=' + id;
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
            
            function popupWinSub(id,subId) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?newDocumentSub&idStaff=' + id + '&idSubRef=' + subId;
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
        </script>
        <style>
            .validateTips { border: 1px solid transparent; padding: 0.3em; color: red; font-weight: bold}
        </style>
    </head>
    <body>
        <s:useActionBean beanclass="exatrez.stripes.util.ListUtil" var="list"/>
        <s:form beanclass="exatrez.stripes.action.ShipVisit3FlowAction" name="form1">   
            <s:hidden name="counterId" />
            <s:hidden name="currentYear" />
            <div>
                <fieldset>
                    <div id="page-title">
                        <span class="title">Ship Visit</span>
                    </div>
                    <c:if test="${!empty(actionBean.listCounter)}">
                        <div style="align: center">
                            <span class="sub-title">Ship visit target as per year ${actionBean.currentYear}</span>
                            <display:table class="tablecloth" name="${actionBean.listCounter}" requestURI="/shipVisit3Flow" id="line" style="width:50%">
                                <display:column title="Target Visit" property="target"/>
                                <display:column title="No. of visit" property="visited"/>
                                <display:column title="Total Balance"><c:out value="${line.target - line.visited}" /></display:column>                 
                            </display:table>
                        </div>
                    </c:if>
                    <div id="page-title">
                        <span class="title">Ship Visit - New Form</span>
                    </div>
                    <s:messages/>
                    <s:errors/>
                    <p class="validateTips"><em>All form fields are required except Attachment.</em></p>
                    <p>
                        <label>Vessel Name :</label>
                        <s:select name="shipVisit3.vessel.vesselId" id="vesselId" style="width:200px">
                            <s:option value="">Please Choose</s:option>
                            <s:options-collection collection="${list.vesselList}" label="vesselName" value="vesselId"/>
                        </s:select>
                    </p>
                    <p>
                        <label>Date Visit :</label>
                        <s:text name="shipVisit3.dateVisit" id="datepicker" formatType="date" formatPattern="dd/MM/yyyy" readonly="true"/>     
                    </p>
                    <p>
                        <label>Location / Port :</label>
                        <s:text name="shipVisit3.location" id="location" size="55" class="uppercase"/>     
                    </p>
                    <c:set var="c" value="0" />
                    <c:forEach items="${actionBean.listShipVisitMatch}" var="object">
                        <c:set var="c" value="${c+1}" />
                        <p>
                            <label>${object.shipVisitHeader.description} :</label>
                            <c:if test="${empty(object.listMatchSub)}">
                                <c:choose>
                                    <c:when test="${object.shipVisitHeader.inputType eq 'M'}">
                                        <s:textarea name="listDetails" id="details_${c}" rows="4" cols="90"/>
                                    </c:when>
                                    <c:otherwise>
                                        <s:text name="listDetails" id="details_${c}" size="55" class="uppercase" />
                                    </c:otherwise>
                                </c:choose>
                            </c:if>
                            <c:if test="${!empty(object.listMatchSub)}">
                                <s:hidden name="listDetails" id="details_${c}"/>
                                <fieldset>
                                    <div>
                                        <c:set var="d" value="0" />
                                        <display:table class="tablecloth" name="${object.listMatchSub}" id="line2" >
                                            <c:set var="d" value="${d+1}" />
                                            <display:column title="Details" property="shipVisitSub.description" style="font-weight:bold;" />
                                            <display:column title="Action"><s:button name="" value="Upload..." class="btn" onclick="return popupWinSub('${actionBean.staffId}','${line2.shipVisitSub.refShipVisitSubId}');"/></display:column>
                                            <display:column title="Comments">
                                                <c:choose>
                                                    <c:when test="${line2.shipVisitSub.inputType eq 'M'}">
                                                        <s:textarea name="listSubDetails" id="sdetails_${d}" rows="4" cols="60" />
                                                    </c:when>
                                                    <c:otherwise>
                                                        <s:text name="listSubDetails" id="sdetails_${d}" size="55" class="uppercase" />
                                                    </c:otherwise>
                                                </c:choose>
                                            </display:column>                                            
                                        </display:table>
                                    </div>
                                </fieldset>
                            </c:if>
                        </p>
                    </c:forEach>
                    <p>
                        <label>Attachment/s :</label>
                        <s:button name="" value="Upload..." class="btn" onclick="return popupWin('${actionBean.staffId}');" />
                    </p>
                    <br />
                    <p>
                        <label>&nbsp;</label>
                        <s:submit name="submit" value="Submit" class="btn" onclick="return validateEmpty();"/>
                    </p>
                </fieldset>
            </div>
        </s:form>
    </body>
</html>